import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_syt/domain/widgets/custom_dialog.dart';
import 'package:flutter_syt/domain/widgets/dialog_vertification_code.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:flutter_syt/utils/utils_dlog.dart';
import 'package:flutter_syt/widgets/dyt_aliyun_widget.dart';

Future<void> showCommonDialog(context, DialogEntity data,
    {bool hideCanel = false}) async {
  // DialogEntity data = DialogEntity(
  //   title,
  //   ContentWidget,
  //   onCancel,
  //   onOk,
  //   cancelText: cancelText ?? "取消",
  //   okText: okText ?? '确定',
  // );
  return showDialog<void>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return CustomDialog(
        data,
        hideCanel: hideCanel,
      );
    },
  );
}

Future<void> showSingleDialog(context, DialogEntity data) async {
  return showDialog<void>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return CustomSingleDialog(data);
    },
  );
}

Future<void> showVertificationCodeDialog(context,
    {required Function(bool isSuccess) vertifivationBlock}) async {
  return showDialog(
    context: context,
    barrierDismissible: false,
    builder: (context) {
      return DialogVertifivationCode(vertifivationBlock: vertifivationBlock);
    },
  );
}

Future<void> showDytAliyunDialog(context,
    {required DytAliyunStatus status,
    required Function(dynamic data) onSuccess}) async {
  return showDialog(
    context: context,
    barrierDismissible: false,
    builder: (context) {
      return Center(
          child: Container(
              margin: EdgeInsets.symmetric(horizontal: 40.w),
              padding: EdgeInsets.only(
                  top: 5.w, left: 20.w, bottom: 28.w, right: 20.w),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(12), color: Colors.white),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      AutoSizeText(
                        S().captch_check,
                        maxLines: 2,
                        style: TextStyle(
                            color: Colors.black,
                            fontSize: 16,
                            fontWeight: FontWeight.bold),
                      ),
                      GestureDetector(
                          behavior: HitTestBehavior.opaque,
                          onTap: () {
                            Navigator.pop(context);
                          },
                          child: Container(
                            width: 40,
                            height: 40,
                            alignment: Alignment.centerRight,
                            child: Image.asset(
                                'assets/images/service_goods_close.png',
                                width: 15,
                                height: 15),
                          ))
                    ],
                  ),
                  Padding(
                    padding: EdgeInsets.only(bottom: 20),
                    child: Text(
                      S().captch_tips,
                      style: TextStyle(
                          color: Colors.black.withOpacity(0.6),
                          fontSize: 14,
                          fontWeight: FontWeight.bold),
                    ),
                  ),
                  DytAliyunWidget(
                    status: status,
                    onSuccess: (data) {
                      DLog(data);
                      onSuccess(data);
                    },
                  ),
                ],
              )));
    },
  );
}

Future<void> showStopServiceDialog(context, {bool isStop = false}) async {
  return showDialog<void>(
    context: context,
    barrierDismissible: false,
    builder: (BuildContext context) {
      return WillPopScope(
          child: Center(
            child: Container(
                width: 295.w,
                height: 215.w,
                child: Stack(
                  children: [
                    Positioned(
                        top: 51.w,
                        left: 0,
                        right: 0,
                        bottom: 0,
                        child: Container(
                            decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(12.w),
                          color: Colors.white,
                        ))),
                    Positioned.fill(
                        child: Container(
                      decoration: BoxDecoration(
                        // borderRadius: BorderRadius.circular(12.w),
                        // color: Colors.red,
                        image: DecorationImage(
                          image: AssetImage(
                            'assets/icons/icon_stop_bg.png',
                          ),
                          alignment: Alignment.topCenter,
                          fit: BoxFit.fitWidth,
                        ),
                      ),
                      child: Column(
                        children: [
                          SizedBox(height: 51.w),
                          Text(
                            isStop ? S().main_stop : S().main_pause,
                            style: TextStyle(
                                color: Colors.black,
                                fontSize: 20,
                                fontWeight: FontWeight.bold),
                          ),
                          SizedBox(height: 20.w),
                          Expanded(
                              child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Container(
                                // color: Colors.red,
                                margin: EdgeInsets.symmetric(horizontal: 26.w),
                                child: Text(
                                  isStop
                                      ? S().main_stopinfo
                                      : S().main_pauseinfo,
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontSize: 16,
                                      fontWeight: FontWeight.normal),
                                ),
                              )
                            ],
                          ))
                        ],
                      ),
                    )),
                  ],
                )),
          ),
          onWillPop: () async => false);
    },
  );
}
